package com.automannn.practice.mybatis.resultSetHandler;

import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.SimpleExecutor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.executor.result.DefaultResultHandler;
import org.apache.ibatis.executor.resultset.DefaultResultSetHandler;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.transaction.Transaction;
import org.apache.ibatis.transaction.managed.ManagedTransaction;

import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author chenkh
 * @time 2021/11/16 15:04
 */
public class ResultSetHandlerTest {
    public static void main(String[] args) throws SQLException {

        Configuration configuration = new Configuration();

        SqlSource sqlSource = new StaticSqlSource(configuration,"test");

        Executor arg0 = new SimpleExecutor(configuration,null);

        MappedStatement arg1 = new MappedStatement.Builder(configuration,"test",sqlSource, SqlCommandType.SELECT).build();

        BoundSql boundSql= sqlSource.getBoundSql("");

        ParameterHandler parameterHandler = new DefaultParameterHandler(arg1,null,boundSql);

        ResultHandler resultHandler = new DefaultResultHandler();


        ResultSetHandler resultSetHandler = new DefaultResultSetHandler(arg0,arg1,parameterHandler,resultHandler,boundSql, RowBounds.DEFAULT);
        //从原生jdbc对象中，处理结果集
        Statement statement = null;
        //内部有两个逻辑： 1.从result转为对象  ===》  2.将对象返回
        resultSetHandler.handleResultSets(statement);
    }
}
